package com.huike.clues.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;

import java.util.Date;
import java.util.List;

import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;
    @Autowired
    private TbClueMapper tbClueMapper;

    @Override
    @Transactional
    public AjaxResult add(ClueTrackRecordVo tbClueTrackRecord) {
        TbClueTrackRecord tbClueTrack = new TbClueTrackRecord();
        BeanUtils.copyProperties(tbClueTrackRecord, tbClueTrack);
        tbClueTrack.setCreateBy(SecurityUtils.getUsername());
        tbClueTrack.setCreateTime(new Date());
        tbClueTrack.setType("0");
        tbClueTrack.setFalseReason(null);
        tbClueTrackRecordMapper.insert(tbClueTrack);
        TbClue tbClue = new TbClue();
       tbClue.setId(tbClueTrackRecord.getClueId());
       tbClue.setStatus("2");
        tbClueMapper.updateTbClueById(tbClue);
        return AjaxResult.success();
    }

    @Override
    public TableDataInfo list(Long clueId) {
        List<TbClueTrackRecord> tbClueTrackRecords = tbClueTrackRecordMapper.selectList(clueId);


        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setRows(tbClueTrackRecords);
        tableDataInfo.setTotal(tbClueTrackRecords.size());
        tableDataInfo.setCode(200);
        tableDataInfo.setMsg("查询成功");
        return tableDataInfo;

    }
}
